package com.pulse.common.utils;

import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName StringToMultipartFile
 * @Description
 * @Author 陆帅
 * @Date 2024/7/17 10:09
 */
public class StringToMultipartFile {

    public static MultipartFile stringToMultipartFile(String content, String filename, String contentType) throws IOException {
        // 将字符串转换为字节数组
        byte[] bytes = content.getBytes();

        // 使用MockMultipartFile创建MultipartFile
        MultipartFile multipartFile = new MockMultipartFile(filename, filename, contentType, bytes);

        return multipartFile;
    }
}